<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>图片导出测试</title>
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        img {
            width: 100px;
            height: auto;
        }
    </style>
</head>
<body>

<div class="container">
    <form action="/test/picexport" target="_blank" method="post">
        <table class="table table-bordered table-hover table-responsive">
            <tr>
                <th>选择</th>
                <th>序号</th>
                <th>图片预览</th>
                <th>图片地址</th>
            </tr>
            <tr>
                <td><input type="checkbox" name="ids[]" value="1"
                           data-img="/upload/product/91a791ff46592e73f3b37a5e293a0033.jpg"></td>
                <td>1</td>
                <td><img src="/upload/product/91a791ff46592e73f3b37a5e293a0033.jpg" alt=""></td>
                <td></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="ids[]" value="2"
                           data-img="/upload/product/0820505ecba45bc993739ba4152aeecf.jpg"></td>
                <td>2</td>
                <td><img src="/upload/product/0820505ecba45bc993739ba4152aeecf.jpg" alt=""></td>
                <td></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="ids[]" value="3"
                           data-img="/upload/product/ae8deb1ae3139a6e603475441d75680f.jpg"></td>
                <td>3</td>
                <td><img src="/upload/product/ae8deb1ae3139a6e603475441d75680f.jpg" alt=""></td>
                <td></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="ids[]" value="4"
                           data-img="/upload/product/d237442d5a8662c9a997666a652d5693.jpg"></td>
                <td>4</td>
                <td><img src="/upload/product/d237442d5a8662c9a997666a652d5693.jpg" alt=""></td>
                <td></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="ids[]" value="5" data-img="/upload/product/model4.jpg"></td>
                <td>5</td>
                <td><img src="/upload/product/model4.jpg" alt=""></td>
                <td></td>
            </tr>
            <tr>
                <td colspan="4">
                    <input type="hidden" name="files" id="files">
                    <input type="checkbox" name="checkAll"> 全选　
                    <button type="submit" onclick="exports();return false;">导出所选图片</button>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script>
    // 全选逻辑
    $('input[name="checkAll"]').click(function () {
        var _this = $(this);
        var _checked = _this.prop('checked');
        $('input[name="ids[]"]').each(function () {
            var _that = $(this);
            if (_checked) {
                _that.prop("checked", true);
            } else {
                _that.prop("checked", false);
            }
        });
    });

    function exports() {
        // 开始遍历选中的图片
        var ids = [];
        $("input[name='ids[]']:checked").each(function (i) {
            ids[i] = $(this).attr('data-img');
        });
        // 把文件列表放入到临时表单变量中
        $('#files').val(JSON.stringify(ids));
        // 然后提交
        $('form').submit();
    }

</script>
</body>
</html>